package com.chinasoft.goodsManager.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//Jedis连接工具包
public class JedisUtil {
    private static JedisPool jedisPool;
    static {
        InputStream in = JedisUtil.class.getClassLoader().getResourceAsStream("jedis.properties");
        //创建Propertes
        Properties prop = new Properties();
        try {
            prop.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(Integer.valueOf(prop.getProperty("maxTotal")));
        config.setMaxIdle(Integer.valueOf(prop.getProperty("maxIdle")));
        jedisPool = new JedisPool(config,prop.getProperty("host"),Integer.valueOf(prop.getProperty("port")));
    }
    //创建连接对象
    public static Jedis getJedis(){
        return jedisPool.getResource();
    }
    //
}
